import 'dart:convert';
import 'dart:io';

import 'package:flutter_test/flutter_test.dart';

main() {
  const String path = "/Users/shanliu/Desktop/fileDir";

  void dirSearch() {
    FileSystemEntity.isDirectory(path).then((bool isDir) {
      if (isDir) {
        print("This is a Dir");
        final Directory directory = Directory(path);
        directory.list().listen((event) {
          if (event is File) {}
        });
      } else {
        print("This is not a Dir");
      }
    });
  }

  Future<void> dirSearchAsync() async {
    if (await FileSystemEntity.isDirectory(path)) {
      print("This is a Dir");
      final Directory directory = Directory(path);
      await for (var item in directory.list()) {
        if (item is File) {}
      }
    } else {
      print("This is not a Dir");
    }
  }

  void fileConfig() {
    var file = File(path);
    Stream<List<int>> inputStream = file.openRead();
    inputStream.transform(utf8.decoder).transform(LineSplitter()).listen(
      (String line) {
        print('Got ${line.length} characters from stream');
      },
      onDone: () {
        print('file is now closed');
      },
      onError: (e) {
        print("error:" + e);
      },
    );
  }

  test("测试网络请求", () {
    dirSearch();
  });
}
